package com.atzzy.ysmall.ysmall_productserviceimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atzzy.ysmall.ysmall_allService.ProductService.ProductCommontService;
import com.atzzy.ysmall.ysmall_beans.ProductCommentVo;
import com.atzzy.ysmall.ysmall_common.utils.PageHelper;
import com.atzzy.ysmall.ysmall_common.vo.R;
import com.atzzy.ysmall.ysmall_mapper.ProductCommentsMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author JAVAZeng
 * @Date 2022/3/6 15:24
 * @Version 1.0
 */
@Service
@Component
public class ProductCommontServiceImpl implements ProductCommontService {

    @Resource
    private ProductCommentsMapper productCommentsMapper;
    @Override
    public R getProductCommentsById(String productId,int pageNum,int limit) {
        Integer count = productCommentsMapper.SumProductConmments(productId);
        int pageCount = count%limit==0? count/limit : count/limit+1;
        int start = (pageNum-1)*limit;
        List<ProductCommentVo> productCommentsVos = productCommentsMapper.selectCommentByProductId(productId, start, limit);
        R success = new R(201, "success", new PageHelper<ProductCommentVo>(count,pageCount,productCommentsVos));
        return success;
    }
}
